package com.thd.filter;

import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;


import java.nio.charset.StandardCharsets;

/**
 * com.thd.filter.MyGatewayFilter
 *
 * @author: wanglei62
 * @DATE: 2022/4/11 15:09
 **/
@Component
public class MyGlobalFilter implements GlobalFilter, Ordered {
    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {

        String url_1 = "/Login";
        String url = exchange.getRequest().getURI() + "";
        System.out.println("================== url："+ url +" ======================");
        if(url.contains(url_1)){
            return chain.filter(exchange);
        }

        ServerHttpRequest request = exchange.getRequest();
        HttpHeaders headers = request.getHeaders();

        System.out.println("================== 过滤器 ======================");
        // 身份校验
        return chain.filter(exchange);
    }

    @Override
    public int getOrder() {
        return 0;
    }
}
